﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QFlow.Data
{
    public partial class QFlowDbContext
    {
        public void DiscardChanges()
        {
            System.Data.Linq.ChangeSet changes = this.GetChangeSet();
            foreach (var item in changes.Inserts)
            {
                this.GetTable(item.GetType()).DeleteOnSubmit(item);
            }

            foreach (var item in changes.Deletes)
            {
                this.GetTable(item.GetType()).InsertOnSubmit(item);
            }

            for (int i = changes.Updates.Count - 1; i >= 0; i--)
            {
                var item = changes.Updates[i];
                this.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, item);
            }
        }

        public void RemoveRecordFromInsertions(object item)
        {
            System.Data.Linq.ChangeSet changes = this.GetChangeSet();
            this.GetTable(item.GetType()).DeleteOnSubmit(item);
        }
    }
}
